<?php

use SidToken\Utils\TrxRpc;

function get_address($uid)
{
    $user = query_user('wallet_address', $uid);
    if (!$user) {
        return null;
    } else {
        return $user['wallet_address'];
    }
}

function getUidByAddress($address)
{
    $key = "WALLET_ADDRESS_{$address}_UID";
    $uid = S($key);
    if (!$uid) {
        $uid = M("Member")->where(['wallet_address' => $address])->getField("uid");
        if (!$uid) {
            $uid = -1;
        }
        S($key, $uid);
    }
    return $uid;
}

function get_account($uid)
{
    $user = query_user('nickname', $uid);
    if (!$user) {
        return null;
    } else {
        return $user['nickname'];
    }
}

function getSharePageUrl()
{
    $urlConfig = C("SID_URL_CONFIG");
    return $urlConfig['shareUrl'];
}

function getApiUrl()
{
    $urlConfig = C("SID_URL_CONFIG");
    return $urlConfig['apiUrl'];
}

function get_user_usdt_balance($uid)
{
    $WalletUtil = new \SidToken\Utils\MemberWalletUtil();
    $ret = $WalletUtil->getWallet($uid);
    return $ret['usdt'];
}

function get_user_sid_balance($uid)
{
    $WalletUtil = new \SidToken\Utils\MemberWalletUtil();
    $ret = $WalletUtil->getWallet($uid);
    return $ret['sid'];
}

/**
 * 根据trx 地址获得用户平台uid
 * @param $address
 * @return int
 */
function get_uid_by_address($address)
{
    $key = "address_uid_{$address}";
    $data = S($key);
    if (!$data) {
        $data = $member = D("Member")->where(['wallet_address' => $address])->getField("uid");
        S($key, $data);
    }
    return intval($data);

}